package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TApplicationInfo;
import com.ruoyi.system.service.ITApplicationInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 报考信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-13
 */
@Controller
@RequestMapping("/system/info")
public class TApplicationInfoController extends BaseController
{
    private String prefix = "system/info";

    @Autowired
    private ITApplicationInfoService tApplicationInfoService;

    @RequiresPermissions("system:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询报考信息列表
     */
    @RequiresPermissions("system:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TApplicationInfo tApplicationInfo)
    {
        startPage();
        List<TApplicationInfo> list = tApplicationInfoService.selectTApplicationInfoList(tApplicationInfo);
        return getDataTable(list);
    }

    /**
     * 导出报考信息列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "报考信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TApplicationInfo tApplicationInfo)
    {
        List<TApplicationInfo> list = tApplicationInfoService.selectTApplicationInfoList(tApplicationInfo);
        ExcelUtil<TApplicationInfo> util = new ExcelUtil<TApplicationInfo>(TApplicationInfo.class);
        return util.exportExcel(list, "报考信息数据");
    }

    /**
     * 新增报考信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报考信息
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "报考信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TApplicationInfo tApplicationInfo)
    {
        return toAjax(tApplicationInfoService.insertTApplicationInfo(tApplicationInfo));
    }

    /**
     * 修改报考信息
     */
    @RequiresPermissions("system:info:edit")
    @GetMapping("/edit/{applicationId}")
    public String edit(@PathVariable("applicationId") Long applicationId, ModelMap mmap)
    {
        TApplicationInfo tApplicationInfo = tApplicationInfoService.selectTApplicationInfoByApplicationId(applicationId);
        mmap.put("tApplicationInfo", tApplicationInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存报考信息
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "报考信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TApplicationInfo tApplicationInfo)
    {
        return toAjax(tApplicationInfoService.updateTApplicationInfo(tApplicationInfo));
    }

    /**
     * 删除报考信息
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "报考信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tApplicationInfoService.deleteTApplicationInfoByApplicationIds(ids));
    }

    @Log(title = "报考信息导入", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:info:import")
    @PostMapping("/importData")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult importData(MultipartFile file, boolean updateSupport,String years) throws Exception
    {
        ExcelUtil<TApplicationInfo> util = new ExcelUtil<TApplicationInfo>(TApplicationInfo.class);
        List<TApplicationInfo> userList = util.importExcel(file.getInputStream());
        String message = tApplicationInfoService.importData(userList, updateSupport, getLoginName(),years);
        return AjaxResult.success(message);
    }

    @RequiresPermissions("system:info:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<TApplicationInfo> util = new ExcelUtil<TApplicationInfo>(TApplicationInfo.class);
        return util.importTemplateExcel("报考数据模板");
    }
}
